
package intopo.demonstrator.partnerclassification;

/**
 * Statistics concerning the partner classification model.  State information that is not necessary to record for history purposes goes into this class.
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 10 de Julho de 2011
 */
public class Statistics
{
	/**
	 * The parameters of the partner classification model.
	 */
	final Parameters parameters;
	/**
	 *  Games played with each partner
	 */
	 java.util.LinkedHashMap<Partner, PartnerData> partnerData;
	 /**
	  * How many games have been played.
	  */
	 int gamesPlayed;
	/**
	 * Construct a new instance of this class
	 * @param parameters
	 */
	public Statistics (Parameters parameters)
	{
		this.parameters = parameters;
		this.partnerData = new java.util.LinkedHashMap<Partner, PartnerData> ();
		for (Partner p : parameters.getPartners()) {
			this.partnerData.put(p, new PartnerData (p));
		}
		this.gamesPlayed = 0;
	}
	public PartnerData getPartnerData (Partner p)
	{
		return this.partnerData.get (p);
	}
	public int getGamesPlayed ()
	{
		return this.gamesPlayed;
	}
	public String toString ()
	{
		StringBuffer result = new StringBuffer (this.partnerData.size () * 5);
		for (PartnerData pd : this.partnerData.values ()) {
			result.append (' ');
			result.append (pd.toString ());
		}
		return result.toString ();
	}
	static public class PartnerData
		implements java.lang.Comparable<PartnerData>
	{
		/**
		 * The partner represented by this instance.
		 */
		final Partner partner;
		/**
		 * Games played with this partner
		 */
		int gamesPlayed;
		PartnerData (Partner partner)
		{
			this.partner = partner;
			this.gamesPlayed = 0;
		}
		public int compareTo (PartnerData other)
		{
			return this.partner.compareTo (other.partner);
		}
		/**
		 * get the number of games played with this partner.
		 * @return the number of games played with this partner.
		 */
		public int getGamesPlayed ()
		{
			return this.gamesPlayed;
		}
		/**
		 * Get the partner represented by this instance.
		 * @return the partner represented by this instance.
		 */
		public Partner getPartner ()
		{
			return this.partner;
		}
		public String toString ()
		{
			return String.format ("%d %s", this.gamesPlayed, this.partner.getBehaveAcceptablyProbability ().toString ());
		}
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
